<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<script type="text/javascript">
function deleteBoard(){
	if(confirm("삭제하시겠습니까?")){
		location.href="board.do?mode=delete&no=${param.no }&category=${requestScope.cvo.bvo.category }";
	}
}
function updateBoard(){
	if(confirm("수정하시겠습니까?")){
		location.href="board.do?mode=updateView&no=${param.no }";
	}
} 

$(document).ready(function(){
	$("#a_img").hide();
	$("#b_td").toggle(function(){
		var ht = '<img src="/img/upload_bo/${requestScope.cvo.bvo.newfilename }"  >';
		$("#b_td").html(ht);
		$("#help").text("원본 이미지 입니다.");
		
		
	},function(){
		var ht = '<img src="/img/upload_bo/${requestScope.cvo.bvo.newfilename }" width="100%" height="100%" >';
		$("#b_td").html(ht);
		$("#help").text("변경된 이미지 입니다.");
	});
	
	$("#replyBtn").click(function(){
		//alert($("#content").val());
		 $.ajax({
		type:"POST",
		url:"board.do",
		data:"mode=reply_write&board_no=${param.no}&m_uid=${sessionScope.mvo.uId }&content="+$("#content").val()+"&restep="+$("#restep").val(),
		dataType:"json",
		success:function(jsonData){ // data 변수로 json 입력된다.						
			// function 을 인자값으로 하여 table 처리 
			$("#board_reply").html(function(){	
				var id = "${sessionScope.mvo.uId }";
				var level = "${sessionScope.mvo.level }"; // 관리자권한 추가
				
				var obj=jsonData.list;
				var table="<table  width = '780px' border = '0' align='center' style='border-collapse: collapse; border-top-style: none;'>";
				for(i=0;i<obj.length;i++){
					table+="<tr style='border: 0'>";
					table+="<td width='10'><input type='hidden' id='restep' value='"+obj[i].RESTEP+"'></td>";
					table+="<td style='border: 0' width='30'>→</td>";
					table+="<td style='border: 0' width='100'>"+obj[i].M_NICKNAME+"</td>";
					table+="<td style='border: 0' width='600'>"+obj[i].CONTENT+"</td>";
					table+="<td style='border: 0' width='50'>"+obj[i].W_DATE+"</td>";	
					if(obj[i].M_UID == id || level == "99"){
						/* table+="<td style='border: 0' width='50' id='updateReply' >수정</td>"; */
						table+="<td style='border: 0' width='50'>";
						table+="<a href='board.do?mode=reply_delete&no="+obj[i].REPLY_NO+"&ref=${requestScope.cvo.bvo.no}&restep="+obj[i].RESTEP+"'>삭제</a>";
						table+="</td>";
					}
					table+="</tr>";
				}
				table+="</table>";
				return table; 
				});//html
				$("#content").val("");
			}// success
		}); // ajax 
	});// replyBtn click
	
});// document



</script>

<table width = "80%" border = "1" align="center" style="border-collapse: collapse;">
	<c:if test="${requestScope.cvo.bvo.newfilename!=null }">
		<tr>
			<td colspan="4" align="center">
				<div id="help">클릭하면 원본이미지</div>
			</td>
		</tr>
		<tr >
			<td colspan="4" id="b_td">
				<img src="/img/upload_bo/${requestScope.cvo.bvo.newfilename }" width="100%" height="100%" >				
			</td>
		</tr>
	</c:if>
		<tr>
			<td >${requestScope.cvo.bvo.memberVO.nickname }</td><td>${requestScope.cvo.bvo.count }</td><td>${requestScope.cvo.bvo.w_data }</td><td>${requestScope.cvo.bvo.category }</td>
		</tr>
		<tr>
			<td colspan="4">제목 : ${requestScope.cvo.bvo.title }</td>
		</tr>
		<tr>
			<td colspan="4">${requestScope.cvo.bvo.contents}</td>
		</tr>
	
						
	<tr>
		<td align="left" colspan="4"  style="border: 0">
			<a href="board.do?mode=list&category=${requestScope.cvo.bvo.category }">
			목록보기</a>&nbsp;&nbsp;
			
			<c:if test="${requestScope.cvo.bvo.memberVO.uId==sessionScope.mvo.uId || sessionScope.mvo.level=='99'}">
																						<!-- 관리자권한 추가 -->
			 <a href="javascript:updateBoard()">수정</a>&nbsp;&nbsp;
			 <a href="javascript:deleteBoard()">삭제</a> 
			</c:if>
		</td>
	</tr>
	<c:if test="${sessionScope.mvo.uId!=null }">	
		<tr style="border: 0">
	 		<td colspan="3" style="border: 0">
     			<textarea style="width: 690px; height:50px;" rows="2" id="content" ></textarea>
     		</td>
     		<td style="border: 0">
     			 <input type="Button" id="replyBtn" value="댓글입력" style="width: 100px;height: 50px;">
     		</td>
		</tr>
	</c:if>
	</table>
	
	<table>
	<tr>
		<td colspan="7" height="40">
			<!-- 목록보기와 띄워놓기 위해 사용함 -->
		</td>
	</tr>
</table>

	<div id="board_reply">
		<table  width = "780px" border = "0" align="center" style="border-collapse: collapse; border-top-style: none;">
			<c:forEach items="${requestScope.cvo.list }" var="reply">
				<tr style="border: 0">
					<td><input type="hidden" id="restep" value="${reply.RESTEP }"></td>
					<td style="border: 0" width="30">→</td>
					<td style="border: 0" width="100"> ${reply.M_NICKNAME}</td>
					<td style="border: 0" width="600">${reply.CONTENT}</td>
					<td style="border: 0" width="50"> ${reply.W_DATE}</td>
					<c:if test="${reply.M_UID==sessionScope.mvo.uId || sessionScope.mvo.level=='99'}"> 
																		<!-- 관리자권한 추가 -->
						<td style="border: 0" width="50">
							<a href="board.do?mode=reply_delete&no=${reply.REPLY_NO}&ref=${requestScope.cvo.bvo.no}&restep=${reply.RESTEP }">삭제</a>
						</td>
					</c:if>
				</tr>
			</c:forEach>
		<tr>
			<td colspan="7" height="40">
				<!-- 목록보기와 띄워놓기 위해 사용함 -->
			</td>
		</tr>
		</table>
	</div>
